#include "geometry.h"
#include "model.h"
#include "tgaimage.h"
#include "draw2d.h"

int main(int argc,char** argv)
{
    int w=800,h=600;
    Model *model;
    Draw2d *draw;
    TGAColor white(255,255,255,255);
    if(argc==2)
    {
        model=new Model(argv[1]);
    }
    else 
    {
        model=new Model("obj/african_head.obj");
    }
    TGAImage *image=new TGAImage(w,h,3);
    for(int i=0;i<model->nfaces();i++)
    {
        std::vector<int> face=model->face(i);
        for(int j=0;j<3;j++)
        {
            Vec3f v0=model->vert(face[j]);
            Vec3f v1=model->vert(face[(j+1)%3]);
            int x0=(v0.x+1.)*w/2.;
            int y0=(v0.y+1.)*h/2.;
            int x1=(v1.x+1.)*w/2.;
            int y1=(v1.y+1.)*h/2.;
            draw->line(image,x0,y0,x1,y1,white);
        }
    }
    image->flip_vertically();
    image->write_tga_file("head.tga");
    return 0;
}